/*
--如何解析  Frame
  - Simple String : "+OK\r\n"
  - error: "-Error message\r\n"
  - Bulk errors: "!<length>\r\n<error>\r\n"
  - integers: ":[<+|->]<value>\r\n"
  - bulk String: "$<length>\r\n<data>\r\n"
  - null bulk string : "$-1\r\n"
  - array : "*<number-of-elements>\r\n<element-1>...<element-n>"
  - null array: "*-1\r\n"
  - null: "_\r\n"
  - boolean: "#<t|f>\r\n"
  - double: ",[<+|->]<integral>[.<fractional>][<E|e>[sign]<exponent>]\r\n"
  - Big numbers: "([+|-]<number>\r\n"  

  - map: "%<number-of-entries>\r\n<key-1><value-1>...<key-n><value-n>"
  - set: "~<number-of-elements>\r\n<element-1>...<element-n>"
*/

use crate::resp::{RespDecode, RespError,RespFrame, SimpleString};
use anyhow::Ok;
use bytes::BytesMut;

// 拿到  bytemut, 对byteMut 进行  解析 

impl RespDecode for RespFrame {
    fn decode(buf: &mut BytesMut) -> anyhow::Result<Self,RespError> {
        let mut iter = buf.iter().peekable();
        match iter.peek(){
            Some(b'+') => {
                todo!()
            }
            _ => todo!(),


        }
    }
}

// impl RespDecode for SimpleString {
//     fn decode(buf: &mut BytesMut) -> Result<Self,RespError> {
//        let len = buf.len();
 
//        if len < 3 {
//           return Err(RespError::NotComplete);
//        }

//        if !buf.starts_with(b"+") {
//             return Err(RespError::InvalidFrameType(format!(
//                 "expect: SimpleString(+) got :{:?}",buf
//             )));
//        }

//        let mut end = 0;
//        if !buf.ends_with(b"\r\n"){
//         return Err(RespError::InvalidFrameType(
//             "expect: end with \r\n".to_string()
//         ));
//        }

//        let data = buf.split_to(len -2);
//        let s = String::from_utf8_lossy(&data[1..end]);
//        Ok(SimpleString::new(s.to_string()))
     
//     }

// }